<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  <link rel="stylesheet" href="../../css/animate.css">
  <link rel="stylesheet" href="../../iconfont/iconfont.css">
  <link rel="stylesheet" href="../../css/mescroll.css">
  <link rel="stylesheet" href="../../css/gloab.css">
  <title>编辑广告</title>
  <style>
    .none-order{
      text-align: center;
      color:#727272;
      line-height: 200%;
      margin-top: 1rem;
    }
    .mescroll{
      position: fixed;
      top: 0;
      bottom: 0;
      height: auto; /*如设置bottom:50px,则需height:auto才能生效*/
    }
    .zz-img{
      width:2.5rem;
      margin:0 auto;
      background:#eee;
      height:2.5rem;
      padding:auto;
      border:1px solid #dedede;
      border-radius:0.05rem;
    }
    .zz-img img{
      width:1rem;
      margin-left:0.75rem;
      margin-top:0.3rem;
    }
    .zz-img div{
      text-align:center;
      line-height:0.45rem;
      height:0.45rem;
      margin-top:0.35rem;
      font-size:0.3rem;
      color:#999;
    }
    .zz-content{
      width:90%;
      height:0.45rem;
      line-height:0.45rem;
      text-align:center;
      margin:0.25rem auto;
      font-size:0.25rem;
      color:#999;
    }
    .zz-image{
      width:5.25rem;
      height:2.65rem;
      margin:auto;
      background: #eee;
      /*overflow: hidden;*/
    }
    .zz-image img{
      width:100%;
      height: 100%;
    }
    .zz-images{
      width:85%;
      height:3rem;
      margin:0.2rem auto;
      background: #eee;
      /*overflow: hidden;*/
    }
    .zz-img-button-list{
      width:85%;
      height:1rem;
      margin:auto;
      line-height: 1rem;
    }
    .zz-img-button-list div{
      width:30%;
      float: left;
      font-size: 0.3rem;
    }
    .zz-img-button-list img{
      width:20%;
      line-height: 1rem;
      margin-top: 0rem;
      padding-top:0.2rem;
    }
    .zz-img-button-list span{
      margin-top: 0rem;
      font-size: 0.3rem;
    }
    .zz-images img{
      width:100%;
      height: 100%;
    }
    .zz-title{
      width:85%;
      height:0.45rem;
      line-height: 0.45rem;
      margin:0 auto 0.25rem;
      font-size: 0.3rem;
    }
    .zz-button{
      width:60%;
      height:0.65rem;
      text-align: center;
      background: #3b8bff;
      line-height: 0.65rem;
      margin:1rem auto;
      color:#fff;
      border-radius: 0.08rem;
    }
  </style>
</head>
<body>
  <div id="app">
    <div id="public-header">
      <div id="statusbar"></div>
      <header class="public-header">
        <div class="public-header-lf iconfont icon-fanhui" @click="javascript:api.closeWin();"></div>
        <div class="public-header-title">编辑广告</div>
      </header>
    </div>
    <div class="dating-body auto" style="padding-bottom:0.5rem;padding-top:1rem;">
          <div class="zz-img" style="" @click="uploadAvatar">
            <img src="../../image/public/add.png" alt="">
            <div>发布站长广告</div>
          </div>
          <div class="zz-content">只支持.jpg格式，大小为宽525px高265px</div>
          <div class="zz-image" style="position:relative;top:0;">
            <img src="../../image/public/up3.png" alt="" style="width: 0.3rem;height:0.3rem;position:absolute;right:-0.1rem;top:-0.1rem;" @click="del">
              <img :src="apiUrl+images" alt="" v-if="images&&images.length>0">
          </div>
          <div class="zz-title" style="margin-top:1rem;">
            广告跳转
          </div>
          <div class="zz-title" style="border-bottom:1px solid #999;padding-bottom:0.15rem;">
            <input type="text" v-model="url" placeholder="请输入跳转链接（选填）">
          </div>
          <div class="zz-button" @click="fabu">编辑广告</div>
      <div class="public-progress" style="z-index:9;">
        <img src="../../icon/icon150x150.png" alt="" class="animated infinite flash" style="width:200px;height:200px;display:block;margin:200px auto;">
      </div>
    </div>
  </div>

</body>
<script src="../../script/api.js"></script>
<script src="../../script/jquery.js"></script>
<script src="../../script/mescroll.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/jsencrypt.js"></script>
<script src="../../script/fastclick.js"></script>

<script>
var vm;
var mescroll;
var mySwiper;
apiready=function(){
  api.removeLaunchView();
  setBar("statusbar");
  setFont(750);
  startVue();
  // NewMescroll();
  var top=$("#public-header").outerHeight(true)+$("#nav").outerHeight(true);
  $("#mescroll").css({"top":top+"px"});
  $(".public-progress").fadeOut(1000);
  setTimeout(function(){
    $(".public-progress").css({"display":"none"});
  },1000);
}
function startVue(){
  vm = new Vue({
    el:"#app",
    data:{
      gdtt:['50','100','200','300','500','1000'],
      num:0,
      banner:["../../image/tg/tg1.jpg","../../image/tg/tg2.jpg","../../image/tg/tg3.jpg"],
      list:[],
      res:['发布广告','管理广告'],
      indexs:'0',
      images:[],
      url:'',
      webValue:[],
      image:[],
    },
    created:function(){
      this.getList();
    },
    mounted:function(){
    },
    methods:{
      del:function(){
        vm.images = '';
      },
      fabu:function(){
        if (vm.images=="") {
          msg('请上传广告图片');
          return;
        }

              api.ajax({
                  url: apiUrl+'api/home/editWebmaster',
                  method: 'post',
                  data: {
                      values: {
                        uid:post_en($api.getStorage('uid')),
                        url:post_en(vm.url),
                        id:api.pageParam.id,
                        image:vm.images,
                      },
                  }
              },function(ret, err){
                  if (ret.status) {
                    msg(ret.msg);
                    setTimeout(function(){
                      api.closeToWin({
                          name: 'root'
                      });
                      api.execScript({
                          name: 'root',
                          script:'qhSelect(0);'
                      });
                    },500)
                  } else {
                    msg(ret.msg);
                  }
              });
      },
      //修改头像
      uploadAvatar:function(){
        var result = hasPermission('photos'); //权限检测
         var text = '为了能够选择图片或文件,请设置相册权限,点击确定前往设置相册权限,点击取消拒绝';
         requestPermission(text, 'photos', result, function(bool) {
             if (bool) {
                 var result = hasPermission('camera'); //权限检测
                 var text = '为了能够拍照,请设置相机权限,点击确定前往设置相机权限,点击取消拒绝';
                 requestPermission(text, 'camera', result, function(bool) {
                     if (bool) {
                       api.actionSheet({
                            cancelTitle:'取消',
                            buttons: ['打开相机', '打开相册']
                        }, function(ret, err) {
                            var index = ret.buttonIndex;
                            if(index==1){
                                vm.getPicture('camera');
                            }else if(index==2){
                                vm.getPicture('album');
                            }
                        });
                     } else {
                       msg("获取当前相机权限失败!");
                     }
                 });
             } else {
                 msg("获取当前相册权限失败!");
             }
         });
      },
         getPicture:function(method) {
              var self = this;
               api.getPicture({
                  sourceType: method,
                  encodingType: 'jpg',
                  mediaValue: 'pic',
                  destinationType: 'url',
                  allowEdit: true,
                  quality: 100,
                  targetWidth:400,
                  targetHeight:400,
                  saveToPhotoAlbum: false
               }, function(rets, err) {
                  if (rets) {
                    var timestamp = (new Date()).getTime();
                    var demo = api.require('imageOptim');
                    demo.compress({ quality: 0.1, width: 600, height: 300, imgPath: rets.data, destinationPath: 'fs://'+timestamp+'.png' }, function (ret, err) {
                        if (ret) {
                          api.ajax({
                              url: apiUrl+'api/home/shangchuanimg',
                              method: 'post',
                              data: {
                                  files: {
                                      file: ret.imgPath
                                  }
                              }
                          },function(ret, err){
                              if (ret.status) {
                                vm.images = ret.data;
                              } else {
                                vm.images = ret.data;
                              }
                          });

                        } else {
                            api.alert({
                                title: '提示',
                                msg: err.message,
                            }, function (ret, err) {
                            });
                        }
                    });
                  }else{
                  }
               });
             },
      getList:function(){
          api.ajax({
              url: apiUrl+'api/home/getWebValue',
              method: 'post',
              data: {
                  values: {
                   id:post_en(api.pageParam.id),
                  },
              }
          },function(ret, err){
              if (ret.status) {
                  vm.images = ret.data['image'];
                  vm.url = ret.url;
              } else {
                vm.images = '';
                vm.url = '';
              }
          });
      },
      more:function(obj){
        if(obj.num){
          vm.page++;
        }else{
          vm.page=1;
          mescroll.lockUpScroll(false);
        }
      },
    }
  })
}
function NewMescroll(){
  mescroll = new MeScroll("mescroll", {
      down:{
        use:true,
        auto:true,
        // autoShowLoading:true,
        callback:vm.more, //下拉刷新的回调,别写成downCallback(),多了括号就自动执行方法了
      },
      up:{
        use:true,
        auto:false,
        lazyLoad: {
          use: true, // 是否开启懒加载,默认false
          attr: 'imgurl', // 网络地址的属性名 (图片加载成功会移除该属性): <img imgurl='网络图  src='占位图''/>
          showClass: 'mescroll-lazy-in', // 图片加载成功的显示动画: 渐变显示,参见mescroll.css
          delay: 500, // 列表滚动的过程中每500ms检查一次图片是否在可视区域,如果在可视区域则加载图片
          offset: 200 // 超出可视区域200px的图片仍可触发懒加载,目的是提前加载部分图片
        },
        callback:vm.more, //上拉刷新的回调,别写成downCallback(),多了括号就自动执行方法了
      }
    })
}
</script>
</html>
